{% extends 'base.html' %}
{% load static %}

{% block title %}编辑设备 - 维修管理系统{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row justify-content-center">
        <div class="col-md-8 col-lg-6">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title mb-0">
                        <i class="bi bi-pencil"></i> 编辑设备：{{ asset.name }}
                    </h4>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        
                        {% if form.errors %}
                        <div class="alert alert-danger">
                            <strong>请修正以下错误：</strong>
                            <ul class="mb-0">
                                {% for field in form %}
                                    {% for error in field.errors %}
                                        <li>{{ field.label }}: {{ error }}</li>
                                    {% endfor %}
                                {% endfor %}
                                {% for error in form.non_field_errors %}
                                    <li>{{ error }}</li>
                                {% endfor %}
                            </ul>
                        </div>
                        {% endif %}

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.name.id_for_label }}" class="form-label">{{ form.name.label }}</label>
                                {{ form.name }}
                                {% if form.name.help_text %}
                                <div class="form-text">{{ form.name.help_text }}</div>
                                {% endif %}
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.model.id_for_label }}" class="form-label">{{ form.model.label }}</label>
                                {{ form.model }}
                                {% if form.model.help_text %}
                                <div class="form-text">{{ form.model.help_text }}</div>
                                {% endif %}
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.asset_type.id_for_label }}" class="form-label">{{ form.asset_type.label }}</label>
                                {{ form.asset_type }}
                                {% if form.asset_type.help_text %}
                                <div class="form-text">{{ form.asset_type.help_text }}</div>
                                {% endif %}
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.serial_number.id_for_label }}" class="form-label">{{ form.serial_number.label }}</label>
                                {{ form.serial_number }}
                                {% if form.serial_number.help_text %}
                                <div class="form-text">{{ form.serial_number.help_text }}</div>
                                {% endif %}
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.purchase_date.id_for_label }}" class="form-label">{{ form.purchase_date.label }}</label>
                                {{ form.purchase_date }}
                                {% if form.purchase_date.help_text %}
                                <div class="form-text">{{ form.purchase_date.help_text }}</div>
                                {% endif %}
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.purchase_price.id_for_label }}" class="form-label">{{ form.purchase_price.label }}</label>
                                {{ form.purchase_price }}
                                {% if form.purchase_price.help_text %}
                                <div class="form-text">{{ form.purchase_price.help_text }}</div>
                                {% endif %}
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.department.id_for_label }}" class="form-label">{{ form.department.label }}</label>
                                {{ form.department }}
                                {% if form.department.help_text %}
                                <div class="form-text">{{ form.department.help_text }}</div>
                                {% endif %}
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="{{ form.status.id_for_label }}" class="form-label">{{ form.status.label }}</label>
                                {{ form.status }}
                                {% if form.status.help_text %}
                                <div class="form-text">{{ form.status.help_text }}</div>
                                {% endif %}
                            </div>
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.notes.id_for_label }}" class="form-label">{{ form.notes.label }}</label>
                            {{ form.notes }}
                            {% if form.notes.help_text %}
                            <div class="form-text">{{ form.notes.help_text }}</div>
                            {% endif %}
                        </div>

                        <div class="d-grid gap-2 d-md-flex">
                            <button type="submit" class="btn btn-primary me-md-2">
                                <i class="bi bi-check-circle"></i> 保存修改
                            </button>
                            <a href="{% url 'assets:asset_detail' asset.pk %}" class="btn btn-outline-secondary me-md-2">
                                <i class="bi bi-x-circle"></i> 取消
                            </a>
                            <a href="{% url 'assets:asset_list_mine' %}" class="btn btn-outline-secondary">
                                <i class="bi bi-list"></i> 返回列表
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
